﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace SmartWallpaperChanger
{
    public class MultipleInstancesHandler
    {
        public static bool IsAlreadyRunning
        {
            get { return GetAlreadyRunningProcess() != null; }
        }

        private static Process GetAlreadyRunningProcess()
        {
            List<Process> processes = new List<Process>(Process.GetProcesses());

            foreach (Process process in processes)
            {
                if (process.ProcessName.Contains("SmartWallpaperChanger") 
                    && !process.ProcessName.Contains("host") 
                    && process.Id != Process.GetCurrentProcess().Id)
                {
                    return process;
                }
            }

            return null;
        }
    }
}
